package com.book.controller;

import com.book.pojo.Order;
import com.book.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: TODO
 * @date 2023/12/20 21:21
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/create")
    public Order createOrder(@RequestParam String productId){
        Order order = orderService.createOrder(productId);
        return order;
    }

    @RequestMapping("/pay")
    public String payOrder(@RequestParam String productId,@RequestParam Float price, @RequestParam Integer payType){
        //Order order = orderService.payOrder(productId);
        String url = orderService.getPayUrl(productId,price,payType);
        return url;
    }

    @RequestMapping("/alipaycallback")
    public String alipayCallback(HttpServletRequest request){
        return orderService.alipayCallback(request);
    }
}
